﻿#include "stdafx.h"
#include "BaseInclude.h"
#include "FrameInclude.h"
#include "SheetView.h"
#include "SheetInterface.h"
#include "LoginUserInfo.h"

#include <typeinfo>
#include <QGraphicsView>


SheetInterface::SheetInterface(QObject *parent) : QObject(parent)
{
	strCurOper = "";
	strCurUser = "";
	LoginUserInfo * pDDLoginUserInfo = LoginUserInfo::getInstance();
	strCurUser = pDDLoginUserInfo->getUserName();
}

SheetInterface::~SheetInterface()
{
	for (int i=0;i<mapOpenSheet.count();i++)
	{
		CHK_POINT_DESTORY(mapOpenSheet.values()[i]);
	}
}

/***********************************************************************************************************************************/
QWidget * SheetInterface::openSheet(int sheetid, int sheetBox)
{
	//是否已经打开
	if (mapOpenSheet.contains(sheetid))
		return mapOpenSheet.value(sheetid);
	//挂载场景
	SheetView * sheetView = new SheetView(sheetid, sheetBox);
	mapOpenSheet.insert(sheetid, sheetView);

	return sheetView;
}

bool SheetInterface::closeSheet(int sheetid)
{
	//清空内存
	if (mapOpenSheet.value(sheetid))
	{
		mapOpenSheet.value(sheetid)->deleteLater();
		mapOpenSheet.remove(sheetid);
		return true;
	}
	return false;
}

bool SheetInterface::closeSheet(QWidget * widget)
{
	if (typeid(*widget) == typeid(SheetView))
	{
		SheetView * pView = (SheetView*) widget;
		int sheetid = mapOpenSheet.key(pView);

		if(sheetid > 0)
		{
		//bool bRet = pView->closeSheet();
			bool bRet = closeSheet(sheetid);
			return bRet;
		}
	}
	return false;
}

int SheetInterface::curOpenSheetCount()
{
	return mapOpenSheet.count();
}



